package org.vectrics.user;

import java.util.HashSet;
import java.util.Iterator;

import org.vectrics.SystemException;

public class PhoneNumberSet extends HashSet {

	public boolean add(Object object) {
		if (object.getClass().equals(PhoneNumber.class)) {
			return(super.add(object));
		} else {
			throw new SystemException("Attempt to add an object that is not of the class PhoneNumber: " + object.getClass().getName());
		}
	}
	
	public boolean contains(Object object) {
		PhoneNumber phoneNumber = null;
		if (object.getClass().equals(String.class)) {
			phoneNumber = new PhoneNumber((String)object);
		} else if (object.getClass().equals(PhoneNumber.class)) {
			phoneNumber = (PhoneNumber)object;
		} else {
			throw new SystemException("contains(object) was passed an incorrect class type: " + object.getClass().getName());
		}
		
		boolean result = false;
		
		Iterator iter = (Iterator)this.iterator();
		while (iter.hasNext()) {
			PhoneNumber current = (PhoneNumber)iter.next();
			if (current.equals(phoneNumber)) {
				result = true;
			}
		}
		return(result);
	}
}
